﻿var _isIE = false;
var isIE6 = false;
var imgsResizeList = {};
function fixImageSize(E, F) {
    var I = imgsResizeList[F];
    var C = I[0],
    L = I[1],
    M = I[2],
    B = I[3],
    A = I[4];
    B = B || 1;
    A = A || 1;
    var K = E.width,
    D = E.height;
    if (K > 0 && D > 0) {
        var H = (L / K < M / D) ? L / K : M / D;
        var O = 0;
        var J = 0;
        if (H <= 1) {
            O = C.width = Math.round(K * H);
            J = C.height = Math.round(D * H)
        } else {
            O = C.width = K;
            J = C.height = D
        }
        if (B == 1) {
            var N = (L - O) / 2;
            C.style.marginLeft = C.style.marginRight = N + "px"
        }
        if (A == 1) {
            var N = (M - J) / 2;
            C.style.marginTop = C.style.marginBottom = N + "px"
        }
    }
    E.onload = null;
    E = null;
    imgsResizeList[F] = null
}
function DownImage(C, I, H, B, A) {
    if (isIE6) {
        var E = (new Date() + "|" + Math.random());
        imgsResizeList[E] = Array.prototype.slice.apply(arguments);
        var F = "<img src='" + C.src + "' onload='fixImageSize(this,\"" + E + "\")' style='position:absolute; visibility:hidden'/>";
        document.body.insertAdjacentHTML("afterBegin", F)
    } else {
        B = B || 1;
        A = A || 1;
        var D = new Image();
        D.onload = function () {
            this.onload = null;
            var K = this.width,
            N = this.height;
            if (K > 0 && N > 0) {
                var M = (I / K < H / N) ? I / K : H / N;
                var O = 0;
                var J = 0;
                if (M <= 1) {
                    O = C.width = Math.round(K * M);
                    J = C.height = Math.round(N * M)
                } else {
                    O = C.width = K;
                    J = C.height = N
                }
                if (B == 1) {
                    var L = (I - O) / 2;
                    C.style.marginLeft = C.style.marginRight = L + "px"
                }
                if (A == 1) {
                    var L = (H - J) / 2;
                    C.style.marginTop = C.style.marginBottom = L + "px"
                }
            }
            C = null
        };
        C.onload = null;
        D.src = C.src
    }
}